#ifndef ITEMREFERENCE_H
#define ITEMREFERENCE_H


#include "models_global.h"
#include "Item.h"


#include <QThread>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QPointer>

//class ItemReferenceFinder;


class MODELSSHARED_EXPORT ItemReference : public Item
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            refItem = other.refItem;
            refName = other.refName;
        }

        QPointer<Item>  refItem;
        QString         refName;
    };

public:

    ItemReference(AbstractItem *parent);
    ItemReference(Item* refItem, AbstractItem *parent);
    ItemReference(const QString& refName, AbstractItem *parent);

    virtual ~ItemReference();

    bool isValid() const;


    virtual int fieldCount() const;
    virtual QString fieldName(const int &data_type) const;
    virtual int field(const QString &field_name) const;

    QString referenceName() const;
    Item*   referenceItem() const;


public slots:

    void refreshReference();


protected:

    virtual QVariant customData(const int &data_type) const;
    virtual void setCustomData(const int &data_type, const QVariant &value);


private:

    QSharedDataPointer<Data> d;
};

#endif // ITEMREFERENCE_H
